package kr.hkit.powerjava.chapter15;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class ColorDlg extends JDialog implements ActionListener, ChangeListener {
	private JColorChooser chooser;
	private JButton okButton;
	private Color color;
	private ChangePanel changePanel;
	
	public ColorDlg(ChangePanel changePanel) {
		this.changePanel = changePanel;
		initialize();
	}
	
	private void initialize() {
		setTitle("색상선택");
		setBounds(100, 100, 650, 431);
		chooser = new JColorChooser(Color.LIGHT_GRAY);
		chooser.getSelectionModel().addChangeListener(this);
		chooser.setBorder(BorderFactory.createTitledBorder("색상선택"));
		add(chooser);
		
		okButton = new JButton("확인");
		okButton.addActionListener(this);
		add(okButton, BorderLayout.SOUTH);
		setVisible(true);
	}

	@Override
	public void stateChanged(ChangeEvent e) {
		color = chooser.getColor();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		changePanel.setChangeColor(color);
		setVisible(false);
	}

}
